import request from "@/utils/request";
const MENU_BASE_URL = "/permissions";

const MenuAPI = {
  getList(queryParams: MenuQuery) {
    return request<any, MenuVO[]>({
      url: `${MENU_BASE_URL}` + "/list",
      method: "get",
      params: queryParams,
    });
  },

  getOptions(onlyParent?: boolean) {
    return request<any, OptionType[]>({
      url: `${MENU_BASE_URL}/getAllPermissions`,
      method: "get",
      params: { onlyParent: onlyParent },
    });
  },

  getFormData(id: string) {
    return request<any, MenuForm>({
      url: `${MENU_BASE_URL}/getPermissionById/${id}`,
      method: "get",
    });
  },

  add(data: MenuForm) {
    return request({
      url: `${MENU_BASE_URL}` + "/createOrUpdate",
      method: "post",
      data: data,
    });
  },

  update(id: string, data: MenuForm) {
    return request({
      url: `${MENU_BASE_URL}/createOrUpdate`,
      method: "post",
      data: data,
    });
  },

  deleteById(id: number) {
    return request({
      url: `${MENU_BASE_URL}/delete/${id}`,
      method: "get",
    });
  },
};

export default MenuAPI;

import type { MenuTypeEnum } from "@/enums/MenuTypeEnum";

export interface MenuQuery {
  keywords?: string;
}

export interface MenuVO {
  children?: MenuVO[];
  component?: string;
  icon?: string;
  id?: string;
  name?: string;
  parentId?: string;
  perm?: string;
  redirect?: string;
  routeName?: string;
  routePath?: string;
  sort?: number;
  type?: MenuTypeEnum;
  visible?: number;
}

export interface MenuForm {
  id?: string;
  parentId?: string;
  name?: string;
  visible: number;
  icon?: string;
  sort?: number;
  routeName?: string;
  routePath?: string;
  component?: string;
  redirect?: string;
  type?: MenuTypeEnum;
  permUrl?: string;
  perm?: string;
  keepAlive?: number;
  alwaysShow?: number;
  params?: KeyValue[];
}

interface KeyValue {
  key: string;
  value: string;
}

export interface RouteVO {
  children: RouteVO[];
  component?: string;
  meta?: Meta;
  name?: string;
  path?: string;
  redirect?: string;
}

export interface Meta {
  alwaysShow?: boolean;
  hidden?: boolean;
  icon?: string;
  keepAlive?: boolean;
  title?: string;
}
